package me.liuyu.ymall.common;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author liuyu E-mail: liuyu2783@163.com
 * @Date 2018/6/21 16:09
 * @Descrption
 * @Modified By
 */
public class YmHttpResponse<T> implements Serializable {
    private String code;
    private String msg;
    private String subCode;
    private String toast;
    private long timestamp = System.currentTimeMillis();
    private T result;

    public YmHttpResponse() {
    }

    public YmHttpResponse(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public YmHttpResponse(String code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    public static <T> YmHttpResponse<T> error(String ret, String msg) {
        return new YmHttpResponse(ret, msg);
    }

    public static <T> YmHttpResponse<T> success() {
        return new YmHttpResponse(YmHttpStatus.OK.toString(), YmHttpStatus.OK.name());
    }

    public static <T> YmHttpResponse<T> success(T result) {
        return new YmHttpResponse(YmHttpStatus.OK.toString(), YmHttpStatus.OK.name(), result);
    }

    public static <T> YmHttpResponse<Map<String, T>> success(String alias, T content) {
        HashMap result = new HashMap();
        result.put(alias, content);
        return new YmHttpResponse(YmHttpStatus.OK.toString(), YmHttpStatus.OK.name(), result);
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return this.result;
    }

    public void setResult(T result) {
        this.result = result;
    }
}
